package org.zpmis.domain.contract.vo;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import org.zpmis.domain.contract.model.Contract;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.List;

@Data
public class ContractVo {
    /**
     * 主键id
     */
    private Long id;

    /**
     * 关联企业id
     */
    private Long companyId;
    /**
     * 合同编号（有规则生成）
     */
    private String code;

    /**
     * 合同名称
     */
    private String name;

    /**
     * 签约日期
     */
    private String contractTime;

    /**
     * 签约说明
     */
    private String contractDesc;

    /**
     * 甲方企业名称
     */
    @JsonProperty(value = "aCompanyName")
    private String aCompanyName;

    /**
     * 甲方企业代表人
     */
    @JsonProperty(value = "aCharge")
    private String aCharge;

    /**
     * 甲方合同洽谈人
     */
    @JsonProperty(value = "aTalkPerson")
    private String aTalkPerson;

    /**
     * 甲方合同洽谈人电话
     */
    @JsonProperty(value = "aTalkMobile")
    private String aTalkMobile;

    /**
     * 乙方企业名称
     */
    @JsonProperty(value = "bCompanyName")
    private String bCompanyName;

    /**
     * 乙方企业代表人
     */
    @JsonProperty(value = "bCharge")
    private String bCharge;

    /**
     * 乙方合同洽谈人
     */
    @JsonProperty(value = "bTalkPerson")
    private String bTalkPerson;

    /**
     * 乙方合同洽谈人电话
     */
    @JsonProperty(value = "bTalkMobile")
    private String bTalkMobile;

    /**
     * 丙方企业名称
     */
    @JsonProperty(value = "cCompanyName")
    private String cCompanyName;

    /**
     * 丙方企业代表人
     */
    @JsonProperty(value = "cCharge")
    private String cCharge;

    /**
     * 丙方合同洽谈人
     */
    @JsonProperty(value = "cTalkPerson")
    private String cTalkPerson;

    /**
     * 丙方合同洽谈人电话
     */
    @JsonProperty(value = "cTalkMobile")
    private String cTalkMobile;

    /**
     * 签订合同类型 1两方合同  2三方合同
     */
    private Integer signMode;
    /**
     * 合同内容
     */
    private String content;

    /**
     * 营业执照（附件）
     */
    private String licenseAttachment;

    /**
     * 合同总金额
     */
    private String totalAmount;

    /**
     * 合同附件
     */
    private String contractAttachment;

    /**
     * 合同备注
     */
    private String remark;

    /**
     * 合同生效日期
     */
    private String effectiveTime;

    /**
     * 合同结束日期
     */
    private String endTime;

    /**
     * 合同类型 1人事 2代理
     */
    private Integer type;

    /**
     * 创建人id
     */
    private Long createId;

    /**
     * 创建人
     */
    private String createPerson;

    /**
     * 创建时间
     */
    private String createTime;


    /**
     * 合同状态 0 待审核 1 已签订 2已过期
     */
    private Integer status;

    /**
     * 账单集合
     */
    @JsonInclude(value = JsonInclude.Include.NON_NULL)
    private List<ContractBillListVo> contractBillListVoList;

    public ContractVo(Contract contract) {
        this.id = contract.getId();
        this.companyId = contract.getCompanyId();
        this.code = contract.getCode();
        this.name = contract.getName();
        this.contractTime =contract.getContractTime() == null ? "" : LocalDateTime.ofInstant(Instant.ofEpochMilli(contract.getContractTime()), ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        this.contractDesc = contract.getContractDesc();
        this.aCompanyName = contract.getACompanyName();
        this.aCharge = contract.getACharge();
        this.aTalkPerson = contract.getATalkPerson();
        this.aTalkMobile = contract.getATalkMobile();
        this.bCompanyName = contract.getBCompanyName();
        this.bCharge = contract.getBCharge();
        this.bTalkPerson = contract.getBTalkPerson();
        this.bTalkMobile = contract.getBTalkMobile();
        this.cCompanyName = contract.getCCompanyName();
        this.cCharge = contract.getCCharge();
        this.cTalkPerson = contract.getCTalkPerson();
        this.cTalkMobile = contract.getCTalkMobile();
        this.signMode = contract.getSignMode();
        this.content = contract.getContent();
        this.licenseAttachment = contract.getLicenseAttachment();
        this.totalAmount = contract.getTotalAmount() == null ? "" : String.valueOf(contract.getTotalAmount());
        this.contractAttachment = contract.getContractAttachment();
        this.remark = contract.getRemark();
        this.effectiveTime = contract.getEffectiveTime() == null ? "" : LocalDateTime.ofInstant(Instant.ofEpochMilli(contract.getEffectiveTime()), ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        this.endTime = contract.getEndTime() == null ? "" : LocalDateTime.ofInstant(Instant.ofEpochMilli(contract.getEndTime()), ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        this.type = contract.getType();
        this.createId = contract.getCreateId();
        this.createPerson = contract.getCreatePerson();
        this.createTime = contract.getCreateTime() == null ? "" : LocalDateTime.ofInstant(Instant.ofEpochMilli(contract.getCreateTime()), ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        this.status = contract.getStatus();
    }
}